package cn.yyljlyy.blog.admin.Controller;

import cn.yyljlyy.blog.admin.service.PermissionService;
import cn.yyljlyy.blog.frontend.service.ContextService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @function: cn.yyljlyy.blog.admin.Controller
 * @author: LiJian
 * @data: 2016年11月23日18：47.
 */
@Controller
@RequestMapping("/admin")
public class ContentCtrl {
    public static String STATUS_DELETE = "delete";
    public static String STATUS_DRAFT = "draft";
    public static String STATUS_NORMAL = "normal";

    public static String COMMENT_STATUS_OPEN = "open";
    public static String COMMENT_STATUS_CLOSE = "close";

    private static final long serialVersionUID = 1L;

    @Autowired
    private ContextService contextService;
    @Autowired
    private PermissionService permissionService;

    @RequestMapping("content")
    public String index(Model model){
        model.addAttribute("menu",permissionService.findAll());
        model.addAttribute("delete_count", contextService.countByModuleAndStatus(getModuleName(), STATUS_DELETE));
        model.addAttribute("draft_count", contextService.countByModuleAndStatus(getModuleName(), STATUS_DRAFT));
        model.addAttribute("normal_count", contextService.countByModuleAndStatus(getModuleName(), STATUS_NORMAL));
        model.addAttribute("include", "_index_include.html");
        return "admin/content/index";
    }

    @RequestMapping("content/new")
    public String edit(Model model){
        model.addAttribute("menu",permissionService.findAll());
        model.addAttribute("delete_count", contextService.countByModuleAndStatus(getModuleName(), STATUS_DELETE));
        model.addAttribute("draft_count", contextService.countByModuleAndStatus(getModuleName(), STATUS_DRAFT));
        model.addAttribute("normal_count", contextService.countByModuleAndStatus(getModuleName(), STATUS_NORMAL));
        model.addAttribute("include", "_index_include.html");
        return "admin/content/edit";
    }

    private String getModuleName() {
        return "m";
    }
}